﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string s_min = textBox1.Text;
                string s_max = textBox2.Text;

                int min = (int)Convert.ToInt64(s_min);
                int max = (int)Convert.ToInt64(s_max);
                if (max > min)
                {

                    int j;
                    int flag = 0;//素数标志
                    int[] s = new int[100];
                    int k = 0;

                    for (int i = min; i <= max; i++)
                    {
                        for (j = 2; j < i; j++)
                        {
                            if (i % j == 0)
                            {
                                flag++;
                            }

                        }
                        if (flag == 0)//是素数
                        {
                            s[k] = i;//存素数
                            k++;
                        }
                        else
                        {
                            flag = 0;//标志置0，开启下一轮检测
                        }
                    }
                    for (int a = 0; a < k; a++)
                    {
                        MessageBox.Show(s[a].ToString());
                    }
                }
                else
                {
                    MessageBox.Show("输入错误，请您检查您输入的内容。");
                }
            }
            catch
            {
                MessageBox.Show("输入错误，请您检查您输入的内容。");
            }

        }
    }
}
